package com.ocom.human.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.human.EntityPersonTagRelation;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.request.human.GetByPersonTagVo;
import com.ocom.human.dao.IDaoPersonTagRelation;
import com.ocom.human.service.PersonTagRelationService;
import com.ocom.mysql.aspect.DataSourceAspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class PersonTagRelationServiceImpl extends ServiceImpl<IDaoPersonTagRelation, EntityPersonTagRelation> implements PersonTagRelationService {


    @Autowired
    private IDaoPersonTagRelation dao;

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB, companyId = "comId")
    public List<EntityPersonTagRelation> getByComId(Long comId) {
        QueryWrapper<EntityPersonTagRelation> queryWrapper = Wrappers.query();
        queryWrapper.eq("com_id", comId);
        return this.list(queryWrapper);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB, companyId = "comId")
    public List<EntityPersonTagRelation> getByComPId(Long comId, Integer pId) {
        QueryWrapper<EntityPersonTagRelation> queryWrapper = Wrappers.query();
        queryWrapper.eq("com_id", comId);
        queryWrapper.eq("p_id", pId);
        return this.list(queryWrapper);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB, companyId = "comId")
    public boolean batchDeleteById(Long comId, List<Long> ids) {
        return this.removeByIds(ids);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB, companyId = "comId")
    public boolean batchDeleteByPId(Long comId, Set<Long> pIds) {
        QueryWrapper<EntityPersonTagRelation> queryWrapper = Wrappers.query();
        queryWrapper.eq("com_id", comId);
        queryWrapper.in("p_id", pIds);
        return this.remove(queryWrapper);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB, companyId = "comId")
    public boolean batchSave(Long comId, List<EntityPersonTagRelation> entity) {
        return super.saveBatch(entity);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB, companyId = "comId")
    public List<GetByPersonTagVo> getByPersonTag(Long comId, List<Long> pIds) {
        return dao.getByPersonTag(comId, pIds);
    }
}
